package com.lc.question.dao;

import com.lc.question.pojo.Student;
import com.lc.question.pojo.Teacher;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository("teacherDao")
public interface ITeacherDao {

    @Select("select * from teacher")
    public List<Teacher> teacherList();

    @Select("select * from teacher where tea_Id=#{tea_Id}")
    public Teacher teacherListById(String tea_Id);

    @Insert("insert into teacher values(#{tea_Id},#{tea_name},#{tea_sex},#{office},#{tea_pwd}" +
            ",#{tea_head},#{t_text})")
    public void addTeacher(Teacher teacher);

    @Select("<script>"+
            "select * from teacher where 1=1"+
            "<if test='tea_Id!=null and tea_Id!=\"\"'>"+
                "and tea_Id=#{tea_Id}"+
            "</if>"+
            "<if test='tea_name!=null and tea_name!=\"\"'>"+
                "and tea_name like CONCAT('%',#{tea_name},'%')"+
            "</if>"+
            "<if test='office!=null and office!=\"\"'>"+
                "and office=#{office}"+
            "</if>"+
            "ORDER BY office,tea_Id"+
            "</script>")
    public Teacher teacherById(Teacher teacher);

    @Select("<script>"+
            "select * from teacher where 1=1"+
            "<if test='tea_name!=null and tea_name!=\"\"'>"+
                "and tea_name like CONCAT('%',#{tea_name},'%')"+
            "</if>"+
            "<if test='office!=null and office!=\"\"'>"+
                "and office=#{office}"+
            "</if>"+
            "ORDER BY office,tea_Id"+
            "</script>")
    public List<Teacher> teacherById2(Teacher teacher);

    @Select("<script>"+
            "select count(*) from teacher where 1=1"+
            "<if test='tea_Id!=null and tea_Id!=\"\"'>"+
            "and tea_Id=#{tea_Id}"+
            "</if>"+
            "<if test='tea_name!=null and tea_name!=\"\"'>"+
            "and tea_name like CONCAT('%',#{tea_name},'%')"+
            "</if>"+
            "<if test='office!=null and office!=\"\"'>"+
            "and office=#{office}"+
            "</if>"+
            "</script>")
    public int studentTotal(Student student);
}
